package com.muli.muwai.impl;
import java.sql.Timestamp;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muli.muwai.entity.IntfProfessionDeparment;
import com.muli.muwai.mapper.ProfessionDeparmentMapper;
import com.muli.muwai.service.ProfessionDeparment;
import com.muli.muwai.util.DateUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class ProfessionDeparmentImpl extends ServiceImpl<ProfessionDeparmentMapper, IntfProfessionDeparment> implements ProfessionDeparment {
    @Override
    public void professiondeparment(List<String[]> professiondeparment) {
        List<IntfProfessionDeparment> list=new ArrayList<>();
        for (String[] strings : professiondeparment) {
            IntfProfessionDeparment deparment = new IntfProfessionDeparment();
            deparment.setAmortizedType(strings[0]);
            deparment.setAmortizedDept(strings[1]);
            deparment.setAdminDept(strings[2]);
            //deparment.setAmortizedRate(strings[3]);
            if (strings[3].equals("")) {
                deparment.setAmortizedRate(Double.valueOf(0));
            } else {
                deparment.setAmortizedRate(Double.parseDouble(strings[3]));
            }
            //deparment.setCreatedTime(new Timestamp(new java.util.Date().getTime()));
            try {
                Date date = DateUtils.parseString2Date(strings[4], "yy/MM/dd");
                Timestamp timestamp = new Timestamp(date.getTime());
                deparment.setCreatedTime(timestamp);
            } catch (Exception e) {
                deparment.setCreatedTime(null);
            }
            deparment.setCreatedBy(strings[5]);
            //deparment.setUpdatedTime(new Timestamp(new java.util.Date().getTime()));
            try {
                Date date = DateUtils.parseString2Date(strings[6], "yy/MM/dd");
                Timestamp timestamp = new Timestamp(date.getTime());
                deparment.setUpdatedTime(timestamp);
            } catch (Exception e) {
                deparment.setUpdatedTime(null);
            }
            deparment.setUpdatedBy(strings[7]);
            list.add(deparment);
        }
        saveBatch(list);
    }
}
